package qj.app.mailcreator;

import java.awt.event.KeyEvent;

import qj.tool.jna.KeyboardHandler;
import qj.ui.DesktopUI4;
import qj.util.Clipboard;
import qj.util.MathUtil;
import qj.util.RandomUtil;
import qj.util.ThreadUtil;
import qj.util.funct.F0;
import qj.util.funct.Fs;
import qj.util.funct.P0;

public class MailCreatorMain {
	public static void main(String[] args) {
		// gmail
		// incachild833/incachild167
		final F0<Integer> counter = Fs.f0(831);// MathUtil.counter(831);
		KeyboardHandler.mapPressed(KeyboardHandler.BACKQUOTE, ThreadUtil.async(new P0() {public void e() {
			Integer count = counter.e();
			String name = "incachild" + count;
			String password = "incachild" + (1000-count);
			System.out.println("Creating account: [" + name + "/" + password + "]");
			
			findInput("First name");

			Clipboard.type(name);
			DesktopUI4.type(KeyEvent.VK_TAB);
			Clipboard.type(name);
			DesktopUI4.type(KeyEvent.VK_TAB);
			Clipboard.type(name);
//			DesktopUI4.type(KeyEvent.VK_TAB);

			findInput("Choose a password");
			Clipboard.type(password);
			DesktopUI4.type(KeyEvent.VK_TAB);
			Clipboard.type(password);
//			DesktopUI4.type(KeyEvent.VK_TAB);

			findInput("Security question");
			DesktopUI4.type(KeyEvent.VK_DOWN);
			DesktopUI4.type(KeyEvent.VK_TAB);
			DesktopUI4.type(KeyEvent.VK_TAB);
			Clipboard.type("blah");

			findInput("Birthday");
			Clipboard.type(RandomUtil.birthday("MM/dd/yyyy"));

			findInput("and the Privacy Policy.");
			DesktopUI4.type(KeyEvent.VK_SPACE);
		}}));
	}

	private static void findInput(String name) {
		DesktopUI4.ctrl('F');
		Clipboard.type(name);
		DesktopUI4.type(KeyEvent.VK_ESCAPE);
		DesktopUI4.type(KeyEvent.VK_TAB);
	}
}
